`use strict`
// const sslify = require('koa-sslify').default;
// const koaStatic = require('koa-static');

const koa = require('koa')
const cors = require('koa2-cors');
const route = require('koa-router')();
const https = require('https');
const http = require('http');
const bodyParse = require('koa-bodyparser');
const fs = require('fs');

const verify = require('./utils/verifyToken')




const app = new koa()
app.use(bodyParse())
app.use(verify())
// 路由
//前端部分
var register = require('./route/login/register')//注册
var login = require('./route/login/login')//登录
var wx_login = require('./route/login/wxLogin')//登录
var user_info = require('./route/user/info')//获取个人信息
var set_info = require('./route/user/setinfo')//修改个人信息
var bill_class_list = require('./route/bill/class')//前端获取分类列表
var add_bill = require('./route/bill/upBill')//添加账单
var get_bill = require('./route/bill/getBill')//获取账单





app.use(register.routes())
app.use(login.routes())
app.use(wx_login.routes())
app.use(user_info.routes())
app.use(bill_class_list.routes())
app.use(add_bill.routes())
app.use(set_info.routes())
app.use(get_bill.routes())



// 后台管理部分
var user_list = require('./route/admin/getUserList')//获取用户列表
var admin_classify = require('./route/admin/getAdminClass')//获取分类列表
var admin_up_classify = require('./route/admin/upAdminClass')//上传分类

app.use(user_list.routes())
app.use(admin_classify.routes())
app.use(admin_up_classify.routes())
//--------------路由结束



app.use(cors())


var data = '123'

app.use(async(ctx,next)=>{
    console.log('123')
    await next()
})
// route.post(async(ctx,next)=>{
//     console.log(123)
//     await next()
// })
route.post('/changeData',async(ctx)=>{
    ctx.body = 'ok'
})


app.use(route.routes())

http.createServer(app.callback()).listen(3000);
const options = {
key: fs.readFileSync("./ssl/2_api.jxqizhou.com.key", "utf8"),
cert: fs.readFileSync("./ssl/1_api.jxqizhou.com_bundle.crt", "utf8")
};
https.createServer(options, app.callback()).listen(440);
